Visualizing Returns


Kerry Back

BUSI 721, Fall 2022
JGSB, Rice University

Let’s look at the history of stock market returns - either the U.S. market as a whole or individual stocks or funds.


We’ll do this with several different plot types:


-scatter plot of returns by year
- box plot of annual returns
- accumulation (1+r1)⋯(1+rn) by year
- accumulation by year with log scale

Box Plot

  • Box contains 25th percentile through 75th percentile

  • Median is indicated in the box

  • Fences extend 1.5 times inter-quartile range from 25th and 75th percentiles or to the most extreme observation if that is closer to the box (inter-quartile range = 75th percentile - 25th percentile)

  • Points outside the fences are outliers (if you simulate data from a normal distribution, there will typically be very few points outside the fences)

Investment Library Rice

Market data is from Kenneth French’s data library


Value-weighted return of all NYSE, AMEX, and Nasdaq stocks from CRSP

(Center for Research in Security Prices at U of Chicago)  


from pandas_datareader import DataReader as pdr
df = pdr('F-F_Research_Data_Factors','famafrench', start=1927)[1]
mkt = df['Mkt-RF'] + df['RF']
mkt /= 100

To see all of the filenames in French’s data library:

from pandas_datareader.famafrench import get_available_datasets as gad
gad()



pdr downloads each file as a dictionary. Each contains a ‘DESCR’ key. The value of that key is a string that explains the other key/value pairs in the dictionary.

filename = 'F-F_Research_Data_Factors'
dct = pdr(filename, 'famafrench', 1927)
print(dct['DESCR'])

Accumulation Point

  • It is easy to plot what $1 would grow to after n periods: \[ (1+r_1)⋯(1+r_{\text{n}}) \]

  • But, when the time period is long, it may be hard to see what happened in the early years, due to exponential growth.

Example



Let’s look at accumulations from two hypothetical stocks.

It will appear that stock 2 did nothing before 2000 and earned a lot less than stock 1 even after 2000.

But the returns are


  • stock 1: 10% per year
  • stock 1: 2% per year until 2000 and 10% afterwards

Example

Log Plots

Consider a function of time y(t). From calculus,

\[ \text{d}logy(t)∝\frac{\text{d}y(t)}{logy(t)}= \text{% change in y} \] where ∝ is = for the natural logarithm.

So a plot of logy(t) reveals the percent changes.

Same Example

Plotting the base 10 logarithm of accumulation:

The exact same plot, but replace 1 on the y axis with \(10^{1}\) and replace 2 with \(10^{2}\).

This means the y axis is in $.

Log Plots with Pandas

Suppose ret is a Series of returns in decimal form indexed by date.

(1+ret).cumprod().plot(logy=True)

Investment Library Rice